package main

import (
	"boke/blogpb"
	"context"
	"fmt"
	"google.golang.org/grpc"
)

// create 发送创建博客请求
func create(cc *grpc.ClientConn) (blogid int64, err error) {
	c := blogpb.NewBlogServiceClient(cc)

	// 创建一个博客
	fmt.Println("创建一个博客")
	blog := &blogpb.Blog{AuthorId: "张三", Title: "一篇博客", Content: "博客内容"}
	createBlogRes, err := c.CreateBlog(context.Background(), &blogpb.CreateBlogRequest{Blog: blog})
	if err != nil {
		// 	log.Panic().Err(err).Msg("创建blog失败")
		return
	}
	fmt.Println("创建成功: Blog has been created: ", createBlogRes.GetBlog().Id, createBlogRes.GetBlog().AuthorId, createBlogRes.GetBlog().Title, createBlogRes.GetBlog().Content)
	blogid = createBlogRes.GetBlog().GetId()
	fmt.Println("Blog has been created id: ", blogid)

	return
}
